<?php
require_once('inc/init.php');
require_once('inc/editor/ubb.php');
if(!isLogin()){
	exit();
}
$id=numFilter($_GET['id']);
$action=strFilter($_GET["action"]);
$action=empty($action)? "view" : $action;
switch($action){
	case "view":
		$msgrow=$db->row_select_one("msgs","id={$id} and touserid={$lg['userid']}");
		$tmp['hasread']=1;
		$msgrow["title"]=htmlFilter($msgrow["title"]);
		$msgrow['fromuser']=empty($msgrow['fromuserid'])?"<span class=\"msg_system\">系统消息</span>":htmlFilter($msgrow['fromuser']);
		$msgrow["posttime"]=getDateStr($msgrow["posttime"]);
		$msgrow['content']=$ubb->ubb2html($msgrow['content']);
		$db->row_update("msgs",$tmp, "id={$id} and touserid={$lg['userid']}");
		require_once getTemplatePath('viewmsg.htm');
		footer(false);
	break;
	
	case "send":
		$username=strFilter($_GET['username']);
		if($id>0){
			$msgrow=$db->row_select_one("msgs","id={$id} and touserid={$lg['userid']}");
			$msgrow["title"]=htmlFilter($msgrow["title"]);
			$msgrow["posttime"]=getDateStr($msgrow["posttime"]);
		}
		if(!empty($username)){
			$msgrow["fromuser"]=$username;
		}
		require_once getTemplatePath('viewmsg.htm');
		footer(false);
	break;
	
	case "del":
		$db->row_delete("msgs","id={$id} and touserid={$lg['userid']}");
		echo("<script>window.parent.delMsg_success();</script>");
	break;
}
?>